const {
  Users
} = require('../utils/db');

//注册用户保存到数据库
const signup = ({
  username,
  password
}) => {
  const users = new Users({
    username,
    password
  });
  return users.save();
}

//查询数据库用户列表
const findList = () => {
  //sort({_id:-1}) 倒序
  return Users.find().sort({
    _id: -1
  })
};

//查询信息
const findUser = (username) => {
  return Users.findOne({
    username
  });
}

//删除用户数据
const remove = id => {
  return Users.findByIdAndRemove(id);
}

module.exports = {
  signup,
  findUser,
  findList,
  remove
}